package com.tx.cms.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tx.cms.actionform.LoginActionForm;
import com.tx.cms.dao.admin.AdminLoginDAO;
import com.tx.cms.manager.AdminManager;

public class LoginAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		LoginActionForm loginForm = (LoginActionForm) form;
		
		String id = loginForm.getId();
		
		String username = loginForm.getUsername();
		
		String password = loginForm.getPassword();

		AdminManager adminLogin = new AdminLoginDAO();
		
		String loginState = adminLogin.adminLogin(id, username, password);
		
		if("success".equals(loginState)) {
			request.setAttribute("username", username);
			
		} 

		return mapping.findForward(loginState);
	}

	
}
